package com.rosesoft.module.mail;

import java.util.List;

import com.rosesoft.frame.utils.SendMail;

/**
 * @FileName CheckThread.java
 * @Description: 所有线程结束后做处理<观察者>
 * @author rose
 * @version 1.0
 * <p>Company: ROSE-SOFT</p>
 * <p>Copyright: Copyright (c) 2010</p>
 */
public class CheckThread extends Thread{
	private ThreadGroup threadGroup ;
	
	private List successList;
	private List failList;
	private SendMail sendMail;
	private StringBuffer successSb;
	private StringBuffer failSb;
	
	public CheckThread(){
		
	}
	public CheckThread(ThreadGroup threadGroup,List successList,List failList,StringBuffer successSb,StringBuffer failSb,SendMail sendMail){
		this.threadGroup = threadGroup;
		this.successList = successList;
		this.failList = failList;
		this.failSb = failSb;
		this.successSb = successSb;
		this.sendMail = sendMail;
	}
	public CheckThread(ThreadGroup threadGroup){
		this.threadGroup = threadGroup;
	}
	  public void run(){
          while(true){
              if(threadGroup.activeCount()==0){
            	  System.out.println("发送成功"+successList.size()+"个");
            	  System.out.println("发送失败"+failList.size()+"个");
            	  
            	  if (!failSb.toString().trim().equals("")) {
          			sendMail.setSubject("发送失败的有"+failList.size()+"个");
          			sendMail.sendMails("qyhdt@sina.com", failSb.toString());
//          			sendMail.sendMails("huiyc180@hkbu.edu.hk", failSb.toString());
          			
          		}
          		sendMail.setSubject("发送成功的有"+successList.size()+"个");
          		sendMail.sendMails("qyhdt@sina.com", successSb.toString());
//          		sendMail.sendMails("huiyc180@hkbu.edu.hk", successSb.toString());
            	return;
              }
          }
      }
}
